//package com.my.study.s3.config;
//
//import com.my.study.s3.bean.S3Bean;
//import com.my.study.s3.properties.AmazonS3Properties;
//import org.springframework.beans.BeansException;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
//import org.springframework.beans.factory.support.BeanDefinitionBuilder;
//import org.springframework.beans.factory.support.BeanDefinitionRegistry;
//import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;
//import org.springframework.beans.factory.support.GenericBeanDefinition;
//import org.springframework.boot.context.properties.EnableConfigurationProperties;
//import org.springframework.context.ApplicationContextAware;
//import org.springframework.context.annotation.Configuration;
//
//import java.util.Map;
//import java.util.concurrent.ConcurrentHashMap;
//
///**
// * @author: yidujun
// * @create: 2021/08/19 13:28
// */
//@Configuration
////@EnableConfigurationProperties(AmazonS3Properties.class)
//public class AmazonS3AutoConfigure implements BeanDefinitionRegistryPostProcessor {
//
//    @Value("${amazon.s3.bucket-names}")
//    private String bucketNames1;
//
//    @Value("${amazon.s3.access-keys}")
//    private String accessKeys1;
//
//    @Value("${amazon.s3.secret-keys}")
//    private String secretKeys1;
//
//
//
////    private AmazonS3Properties amazonS3Properties;
//
//    Map<String, Class<? extends S3Bean>> BEAN_CLASSES = new ConcurrentHashMap<>(16);
//
////    @Autowired
////    public void setAmazonS3Properties(AmazonS3Properties amazonS3Properties) {
////        this.amazonS3Properties = amazonS3Properties;
////    }
//
//    private void init() {
////        String[] bucketNames = bucketNames1.split(",");
////        String[] accessKeys = accessKeys1.split(",");
////        String[] secretKeys = secretKeys1.split(",");
////
////        if (bucketNames.length != secretKeys.length || accessKeys.length != secretKeys.length) {
////            throw new RuntimeException("s3配置错误");
////        }
//
//        for (int i = 0; i < 3; i++) {
//            S3Bean s3Bean = new S3Bean("s" + i, "ak"+i, "sk"+i);
//            BEAN_CLASSES.put("s" + i, s3Bean.getClass());
//        }
//    }
//
//
//    @Override
//    public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {
//        init();
//        BEAN_CLASSES.forEach((beanName, beanClass) -> {
//            BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(beanClass);
//            GenericBeanDefinition definition = (GenericBeanDefinition) builder.getRawBeanDefinition();
//
//            definition.getConstructorArgumentValues().addGenericArgumentValue(beanClass);
//            // 生成bean的bean工厂
//            definition.setBeanClass(S3BeanFactory.class);
//
//            definition.setAutowireMode(GenericBeanDefinition.AUTOWIRE_BY_TYPE);
//
//            registry.registerBeanDefinition(beanName, definition);
//        });
//    }
//
//    @Override
//    public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
//
//    }
//}
